$(function(){
	   $(".cart").hide();
	   $(".add").each(function(){
		   text =parseFloat(2000000) + parseFloat($(this).attr("test")); 
		   var id3 = "#" +text;
		   text = parseFloat(400000) +parseFloat($(this).attr("test"));
			var id6 = "#" + text;
		  $(this).click(function(){
		  var url = "/TradeBook/view/TraderBook_Order/addCount";
		  $.ajax({   
			  type: "POST",  
			  url: url, 
			  data: 'btId=' + $(this).attr("test"),  
			  timeout: 15*1000,
			  success: function(data){		
				  if(data == 'c')
				  {
					  $(".cart").html("已售完！");
					  $(id6).animate({
						  opacity: 'show'
						 }, "slow");
					  $(id6).animate({
						  opacity: 'hide'
						 }, "slow");
				  }else{
				  $("#count").html(data);
				  var count = parseFloat($(id3).val()) +1;
				  $(id3).val(count);
				  };
			  },
			  error:function(result){		           
	            	
	            }
		  });
		  }) ;
	   });
$(".sub").each(function(){
		   
		   $(this).click(function() {	
			   text =parseFloat(2000000) + parseFloat($(this).attr("test")); 
			   var id3 = "#" +text;
				 var url = "/TradeBook/view/TraderBook_Order/subCount";
				 var count = $(id3).val() -1;
			     if(count>0)
				 {$(id3).val(count);	 
					  $.ajax({   
						  type: "POST",  
						  url: url, 
						  data: 'btId=' +  $(this).attr("test"),  
						  timeout: 15*1000,
						  success: function(data){		 
							 $("#count").html(data);
						  },
						  error:function(result){		           
				              	alert("sad");
				          }
					  });	
				 }
			}); 
	   });
$(".delete").each(function(){
	text = parseFloat(5000000) +parseFloat($(this).attr("index"));
	var id5 = "#"+text;
	$(this).click(function(){
		 var url = "/TradeBook/view/TraderBook_Order/remove";
		 $.ajax({   
			  type: "POST",  
			  url: url, 
			  data: 'btId=' + $(this).attr("tbid"),  
			  timeout: 15*1000,
			  success: function(data){
				 var array = data.split(".");
				$("#count").html(array[0]);
				$("#te").html(array[1]);
				if(array[1] == 0)
					{
					  $("#shopCart").html('<div class="nobuy">'+
								'<img src="<%=basePath%>images/cart.gif"/><strong> 购物车内暂时没有商品，您可以去<a href="<%=basePath%>view/TraderBook_Index/TraderBook_Index">首页</a>挑选喜欢的商品</strong>'
							 +	'</div>')
					}
			  },
			  error:function(result){		           
	              	alert("text");
	              }
		  });
		 $(id5).hide();
	});
});
});